import { _decorator, Component, instantiate, Prefab } from 'cc';
import { bundleManager } from '../../Framework/assetsManager/bundleManager/BundleManager';
import { BundleName } from '../../Framework/assetsManager/BundleName';
import { resMananger } from '../../Framework/assetsManager/loader/ResMananger';
import resourcesMap from '../../Framework/assetsManager/resourcesMap';
const { ccclass, property } = _decorator;

@ccclass('TestResLoader')
export class TestResLoader extends Component {
    
    protected onLoad(): void {
        bundleManager.loadBundle(BundleName.Resources)
    }

    start() {
        // res.loadRemote('http://www.cloud.com/test1.jpg', (err, texture) => {
        //     if (err) {
        //         console.log(err);
        //         return;
        //     }
        //     console.log(texture);
        // });

    }


    public clickLoadRes() {
        this._loadResources();
    }

    private async _loadResources() {
        const item_p = await resMananger.loadAsync<Prefab>(BundleName.Resources, resourcesMap.resources.prefab.test);
         item_p.addRef();
        this.node.addChild(instantiate(item_p));
        resMananger.dump();
        this.scheduleOnce(() => {
            item_p.decRef();
            this.scheduleOnce(() => {
                resMananger.dump();
            }, 1)
            
        }, 5);

        
    }
}